//
//  BK_my_couponCommon.m
//  bestkeep
//
//  Created by bj on 2016/11/16.
//  Copyright © 2016年 utouu. All rights reserved.
//

#import "BK_my_couponCommon.h"
#import "RequestManager.h"

@implementation BK_my_couponCommon

NSString * const formalEnvironmentCouponStrBKAPI = @"http://api.bestkeep.cn/";

NSString * const bk_my_couponStrBKAPI = @"http://api.test.bestkeep.cn/";

//兑换码兑换接口（ST验证）
NSString *const userRedeemCodeExchange = @"shopping-tick/userRedeemCodeExchange";


+ (NSString *)formalEnvironment:(NSString *)url {
    if (ApplicationEnvironmentProduction == 1) {
        return [formalEnvironmentCouponStrBKAPI stringByAppendingString:url];
    }
    return [bk_my_couponStrBKAPI stringByAppendingString:url];
}

+ (void)getVoucherShopping:(NSString *)useType pagesize:(NSString *)page_size pageno:(NSString *)page_no callback:(CouponCallback)callback {
    
    NSString *url = [self formalEnvironment:@"shopping-tick/list_v3"];
    NSDictionary *body_dic =[NSDictionary dictionaryWithObjectsAndKeys:useType,@"useType",page_size,@"pagesize",page_no,@"pageno", nil];
   [[RequestManager manager] bkDataRequest:RequestMethodPost URLString:url parameters:body_dic success:^(id  _Nullable responseObject) {
       NSDictionary *dic = responseObject[@"data"];
       callback(dic, nil);
   } failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
       callback(nil, error);
   }];
}

+(void)exchangeCouponByCouponNO:(NSString *)couponNO mycallBack:(CouponCallback)callback{
    
    NSString *url = [self formalEnvironment:userRedeemCodeExchange];
    NSDictionary *body_dic =[NSDictionary dictionaryWithObjectsAndKeys:couponNO,@"code", nil];
    
    [[RequestManager manager] bkDataRequest:RequestMethodPost URLString:url parameters:body_dic success:^(id  _Nullable responseObject) {
        callback(responseObject,nil);
    } failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
        callback(nil, error);
    }];
}


@end
